﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Manon.Autofac;
using Manon.ConfigCenter.Web.ApplicationCore.Interfaces;
using Manon.ConfigCenter.Web.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Manon.ConfigCenter.Web.Controllers
{
    [Route("api/config")]
    [ApiController]
    public class ConfigController : ControllerBase
    {

        [HttpGet("default/{EnvCode}/{ProjectCode}")]
        [BasicAuth]
        public async Task<string> GetProjectOnlineConfigById(string EnvCode,string ProjectCode )
        { 
            var project = Resolver.Resolve<IProjectService>();
            var result = await project.GetProjectOnlineConfigById(ProjectCode, EnvCode);
            if (string.IsNullOrEmpty(result)) return null;
            byte[] b = System.Text.Encoding.Default.GetBytes(result);
            return Convert.ToBase64String(b);
        }
    }
}
